/**
 * 实名认证管理初始化
 */
var Realname = {
    id: "RealnameTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Realname.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '', field: 'realId', visible: true, align: 'center', valign: 'middle',formatter:function (value,row,index) {
                    return index+1;
                }},
            {title: '用户ID', field: 'userId', visible: false, align: 'center', valign: 'middle'},
            {title: '姓名', field: 'trueName', visible: true, align: 'center', valign: 'middle'},
            {title: '签约卡的手机号', field: 'phone', visible: true, align: 'center', valign: 'middle'},
            {title: '证件类型', field: 'cardType', visible: true, align: 'center', valign: 'middle',formatter:Realname.cardType},
            {title: '身份证号码', field: 'cardID', visible: true, align: 'center', valign: 'middle'},
            {title: '证件地址', field: 'cardAddress', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'auditRemark', visible: true, align: 'center', valign: 'middle'},
            {title: '操作IP', field: 'optIP', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'addDatetime', visible: true, align: 'center', valign: 'middle'},
            {title: '操作', field: 'op', visible: true, align: 'center', valign: 'middle',formatter:Realname.op}
    ];
};

Realname.op = function(value,row,index){
    return "<a href='javascript:void(0)' onclick='Realname.openRealnameDetail()'>详情</a>";
};

// 1二代身份证 2香港 3澳门 4台湾 5新加坡
Realname.cardType = function(value,row,index){
    var result = "";
    switch (value){
        case 1:
            result = '二代身份证';
            break;
        case 2:
            result = '香港';
            break;
        case 3:
            result = '澳门';
            break;
        case 4:
            result = '台湾';
            break;
        case 5:
            result = '新加坡';
            break;
        default:
            break;
    }
    return result;
};
/**
 * 检查是否选中
 */
Realname.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Realname.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加实名认证
 */
Realname.openAddRealname = function () {
    var index = layer.open({
        type: 2,
        title: '添加实名认证',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/realname/realname_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看实名认证详情
 */
Realname.openRealnameEdit = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '实名认证编辑',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/realname/realname_update/' + Realname.seItem.realId
        });
        this.layerIndex = index;
    }
};
/**
 * 打开查看实名认证详情
 */
Realname.openRealnameDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '实名认证详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/realname/realname_info/' + Realname.seItem.realId
        });
        this.layerIndex = index;
    }
};

/**
 * 删除实名认证
 */
Realname.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/realname/delete", function (data) {
            Feng.success("删除成功!");
            Realname.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("realnameId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询实名认证列表
 */
Realname.search = function () {
    var queryData = {};
    queryData['trueName'] = $("#trueName").val();
    queryData['phone'] = $("#phone").val();
    queryData['cardID'] = $("#cardID").val();
    Realname.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Realname.initColumn();
    var table = new BSTable(Realname.id, "/realname/list", defaultColunms);
   // table.setPaginationType("client");
    table.setPaginationType("server");
    Realname.table = table.init();
});
